package com.tuo51.childcare.domain.feed;

import com.tuo51.childcare.service.FeedsService;
import com.tuo51.core.domain.org.Organization;
import com.tuo51.core.domain.staffs.Staff;
import com.tuo51.foudation.model.Domain;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;

@Entity
@Table(name = "user_feeds")
@EqualsAndHashCode(callSuper = true)
@Data
public class Feeds extends Domain {

    @Column(columnDefinition = "varchar(32) COMMENT '用户id'")
    private String uid;

    @Column(columnDefinition = "varchar(32) COMMENT '孩子id'")
    private String childrenId;

    @Column(columnDefinition = "varchar(10) COMMENT '孩子姓名'")
    private String childrenName;

    @Column(columnDefinition = " int default 0  COMMENT '宝宝性别 ：0：女，1：男'")
    private Integer gender;

    @Column(columnDefinition = "varchar(10) COMMENT '月龄'")
    private String month;

    @Column(columnDefinition = "varchar(255) COMMENT '标题'")
    private String title;

    @Column(columnDefinition = "varchar(1024) COMMENT '内容'")
    private String content;

    @Column(columnDefinition = "varchar(2048) COMMENT '图片'")
    private String images;

    @Column(columnDefinition = "varchar(1024) COMMENT '视频'")
    private String videos;

    @Column(columnDefinition = "varchar(32) COMMENT '来源staff id'")
    private String sourceStaffId;

    @Column(columnDefinition = "varchar(50) COMMENT '来源机构名称'")
    private String sourceArea;

    @Column(columnDefinition = "varchar(20) COMMENT '老师姓名'")
    private String teacherName;

    @Column(columnDefinition = "varchar(255) COMMENT '老师头像'")
    private String teacherImg;

    @Column(columnDefinition = "INT COMMENT '类型 1,儿心量表  2. 养育环境  3.感悟    4.每日观察记录'")
    private Integer type;

    @Column(columnDefinition = "varchar(32) COMMENT '类型中文'")
    private String typeVal;

    @Column(columnDefinition = "varchar(32) COMMENT '关联id'")
    private String linkId;

    @Column(columnDefinition = "datetime COMMENT '创建时间'")
    private Date created = new Date();

    @Column(columnDefinition = "varchar(255) COMMENT '链接地址'")
    private String url;

    public static Feeds of(String title,
                           Staff sourceTeacher,
                           Organization organization,
                           String childrenId,
                           String childrenName,
                           Integer gender,
                           FeedsService.FeedsType type,
                           String uid, String linkId, Date created){

        Feeds feeds = new Feeds();

        feeds.setCreated(created);

        feeds.setTitle(title);
        if (sourceTeacher != null) {
            feeds.setSourceStaffId(sourceTeacher.getId());
            feeds.setTeacherImg(sourceTeacher.getHeadImgUrl());
            feeds.setTeacherName(sourceTeacher.getRealName());
        }

        if (organization != null)
            feeds.setSourceArea(organization.getName());

        feeds.setChildrenId(childrenId);
        feeds.setChildrenName(childrenName);
        feeds.setGender(gender);
        feeds.setType(type.getType());
        feeds.setTypeVal(type.getTypeVal());

        feeds.setUid(uid);

        feeds.setLinkId(linkId);

        return feeds;
    }
}
